pdf and CDF

Plots of the pdf and CDF of the distribution given in WMS 7th Ed. problme 4.126 are easily generated.

  curve( 6*x*(1-x)*(0 < x & x < 1), from=-0.5, to=1.5, n=100001, ylab="f(x) or F(x)")
  curve( (3*x^2 - 2*x^3)*(0 < x & x < 1) + (x > 1), from=-0.5, to=1.5, n=100001, add=TRUE, lty=2, col=2)

Area Under the Curve

The area under \(f(x)\) between \(x=0.5\) and \(x=0.8\) can also be plotted. The area is equal to the difference \(F(0.8)-F(0.5)\) which is shown in red.

  f <- function(x){6*x*(1-x)*(0<=x)*(x<=1)}
  F <- function(x){0+(3*x^2 - 2*x^3)*(0 < x & x < 1) + (x > 1)}
  cord.x <- c(.5,seq(.5,.8,0.01),.8)
  cord.y <- c(0,f(seq(.5,.8,0.01)),0)
  curve( 6*x*(1-x)*(0 < x & x < 1), from=-0.5, to=1.5, n=100001, ylab="f(x) or F(x)")
  curve( (3*x^2 - 2*x^3)*(0 < x & x < 1) + (x > 1), from=-0.5, to=1.5, n=100001, add=TRUE, lty=2, col=2)  
  polygon(cord.x,cord.y,col='skyblue')
  abline(h=F(.5), lty=3, col=2)
  abline(h=F(.8), lty=3, col=2)
  text(0.65,0.125,"p=0.346", cex=0.75)
  text(-0.4, F(.5), F(.5), col=2, cex=0.75)
  text(-0.4, F(.8), F(.8), col=2, cex=0.75)